/*
 * @Author: zhangweixin 
 * @Date: 2018-11-21 09:59:13 
 * @Last Modified by: zhangweixin
 * @Last Modified time: 2018-12-18 12:14:46
 */
import React,{Component} from 'react';

class Bundle extends Component {
   state = {
     // short for "module" but that's a keyword in js, so "mod"
     mod: null
   }
   componentWillMount() {
    this.load(this.props)
   }
   componentWillReceiveProps(nextProps) {
    if(nextProps.load !== this.props.load){
      this.load(nextProps)
    }
   }
   load(props){
     this.setState({
       mod: null
     })
     props.load((mod)=>{
      //  debugger
      this.setState({
        // handle both es imports and cjs
        mod: mod.default ? mod.default : mod
      })
     })
   }
  render() {
    // console.log(this.props.children)
    // debugger
    return this.props.children(this.state.mod)
  }
}

export default Bundle;